package capstone.tagit;

import java.util.Collection;

import android.graphics.drawable.Drawable;

/**
 * 
 * A wrapper class for the type name and marker to be associated with each tag.
 * Also contains a static method to find a certain TagType, keyed by string,
 * within a collection of TagTypes.
 *
 */
public class TagType {
	String name;
	/**
	 * The icon which will appear on screen for Tags of this TagType.
	 */
	Drawable marker;
	
	/**
	 * Public constructor for a TagType.  Just instantiates name and marker from the given parameters
	 * @param name		The TagType name.
	 * @param marker	The marker for Tags of this TagType.
	 */
	public TagType(String name, Drawable marker){
		this.name=name;
		this.marker=marker;
	}
	
	public String getName(){return name;}
	public Drawable getMarker(){return marker;}
	
	/**
	 * A test for TagType equality.  TagTypes with the same name are considered equivalent.
	 * Note that this means you cannot have multiple TagTypes with the same name.
	 * @param compareTo	
	 * @return			
	 */
	public boolean equals(TagType compareTo){
		return name.equals(compareTo.getName());
	}
	
	/**
	 * Finds a TagType in a Collection of TagTypes from a given string.
	 * @param searchName	The String from which to search for a tag out of the given Collection.
	 * @param types			The Collection of TagTypes eligible for searching.
	 * @return				The TagType matching the given string.  Null if no such type is found.
	 * 		
	 */
	public static TagType findTypeByName(String searchName, Collection<TagType> types){
		for (TagType type : types){
			if (searchName.equals(type.getName())){
				return type;
			}
		}
		return null;
	}
}
